package com.qf.controller;

import com.qf.dto.PageSearchDTO;
import com.qf.entity.MallGoodsSpec;
import com.qf.entity.MallGoodsSpecOptions;
import com.qf.mapper.GoodsSpecMapper;
import com.qf.service.IGoodsSpecService;
import com.qf.vo.PageResult;
import com.qf.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>title: com.qf.controller</p>
 * <p>Company: wendao</p>
 * author zhuximing
 * date 2021/9/16
 * description:
 */
@RestController
@RequestMapping("spec")
@CrossOrigin
public class GoodsSpecController {
    @Autowired
    private IGoodsSpecService goodsSpecService;
    @Autowired
    private GoodsSpecMapper goodsSpecMapper;


    @RequestMapping("page")
    public PageResult<MallGoodsSpecOptions> page(@RequestBody PageSearchDTO<MallGoodsSpecOptions> searchDTO){

        return  goodsSpecService.selectSpecOptsByPage(searchDTO);
    }

    @RequestMapping("save")
    public Result save(@RequestBody MallGoodsSpec spec){
        return  goodsSpecService.saveSpec(spec);
    }
    @RequestMapping("editSpec")
    public Result editSpec(@RequestBody MallGoodsSpec spec){
        return  goodsSpecService.editSpec(spec);
    }
    @RequestMapping("delSpec")
    public Result delSpec(@RequestBody MallGoodsSpecOptions options){
        return  goodsSpecService.delSpec(options);
    }
    @RequestMapping("all")
    public List<MallGoodsSpec> all(){

        return goodsSpecMapper.findAll();
    }
    @RequestMapping("findSpecAndOpts/{templateId}")
    public List<MallGoodsSpec> findSpecAndOpts(@PathVariable String templateId){

        return goodsSpecService.findSpecAndOptsBytemplateId(templateId);
    }

}